// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const organizeCollect = db.collection('kq_organize')
  const thisID = organizeCollect.where({'_id':event._id})

  let userdata = await db.collection('kq_user').where({
    _openid: wxContext.OPENID
  }).get();
  title = userdata.data[0].title;
  mobile = userdata.data[0].mobile;
  

  return thisID.get().then(res => {
    return thisID.update({
      data: {
        member: _.push([{
          _openid:wxContext.OPENID,
          title: title,
          mobile: mobile,
          status:-1
        }])
      }
    })
  })

  // return {
  //   event,
  //   openid: wxContext.OPENID,
  //   appid: wxContext.APPID,
  //   unionid: wxContext.UNIONID,
  // }
}